<?php

namespace app\adminmini\service;

use app\adminmini\model\Make;
use think\facade\Db;

class MakeService extends BaseService
{
    /**
     * 构造函数
     * LevelService constructor.
     */
    public function __construct()
    {
        $this->model = new Make();
    }

    public function updateUserInfo()
    {

        // 参数
        $param = request()->param();

        $data = [
            'integral' => isset($param['integral']) ? $param['integral'] : 0,
            'retreat_price' => isset($param['retreat_price']) ? $param['retreat_price'] : 0,
            'time' => isset($param['time']) ? $param['time'] : 0,
            'price' => isset($param['price']) ? $param['price'] : 0,
            'content' => isset($param['content']) ? $param['content'] : '',
            'store_id' => $this->userId(),
            'door_distance' => isset($param['door_distance']) ? $param['door_distance'] : 0,

        ];

        $info = Db::name('coutomer_make')->where('store_id', '=', $this->userId())->find();
        if ($info) {
            $result = Db::name('coutomer_make')->where('store_id', '=', $this->userId())->update($data);
        } else {
            $result = Db::name('coutomer_make')->insert($data);
        }

        if (!$result) {
            return message("更新资料信息失败", false);
        }
        return message("更新资料信息成功");
    }

    /**
     * 获取用户信息
     * @param $userId 用户ID
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @author 牧羊人
     * @since 2020/11/14
     */
    public function getUserInfo()
    {


        $info = Db::name('coutomer_make')->where('store_id', '=', $this->userId())->find();

        if (!$info) {
            $info['price'] = 0;
        }
        return message("操作成功", true, $info);
    }
}